<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 300px;
            height: 300px;
            background-color: red;
        }

        .change {
            background-color: purple;
            color: salmon;
            font-size: 13px;
            margin-top: 100px;
        }
    </style>
</head>

<body>
    <div>
        4334
    </div>
    <script>
        var div = document.querySelector('div');
        div.onclick = function () {
            //会覆盖原来的类明
            // 如果想要保留原先的类名
            // 就要把原来的类名也写上，空格隔开
            this.className = 'change';
        }
    </script>
</body>

</html>